<template>
    <div>
        <h2>添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">员工编号</td>
                    <td><input type="text" v-model="info.UserCode"></td>
                </tr>
                <tr>
                    <td align="right">姓名</td>
                    <td><input type="text" v-model="info.UserName"></td>
                </tr>
                <tr>
                    <td align="right">角色</td>
                    <td>
                         <select v-model="info.Jid">
                             <option value="">请选择</option>
                             <option :value="item.Id" v-for="item in err">{{ item.JsName }}</option>
                         </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">手机号码</td>
                    <td><input type="text" v-model="info.Userphone"></td>
                </tr>
                <tr>
                    <td align="right">备注</td>
                    <td><input type="text" v-model="info.Userbz"></td>
                </tr>
                <tr>
                    <td align="right">更新人</td>
                    <td><input type="text" v-model="info.Gxname"></td>
                </tr>
                <tr>
                    <td align="right">最后跟新时间</td>
                    <td><input type="date" v-model="info.GxTime"></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td><input type="radio" name="Stares" v-model="info.Stares" :value="true">启用
                    <input type="radio"    name="Stares" v-model="info.Stares" :value="false">禁用</td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios';
import moment from 'moment';
import{useRoute,useRouter}from 'vue-router'
const route=useRoute();
const router=useRouter();
let info:any=reactive({
  "UserCode": moment(new Date()).format('yyyyMMdd')+123,
  "UserName": "",
  "Jid": "",
  "Userphone": "",
  "Userbz": "",
  "Gxname": "",
  "GxTime": "",
  "Stares": "",
})
onMounted(()=>{
    bangding();
})

//绑定下拉框
let err:any=ref([])
const bangding=()=>{
    axios({
        url:'/api/User/Bingjs',
        method:'get'
    })
    .then((res)=>{
        err.value=res.data
    })
}

//添加
const ok=()=>{
    if(info.UserName==""){
        alert("姓名不能为空");
        return;
    }
    if(info.Userphone==""){
        alert("手机号不能为空");
        return;
    }
    if(info.Userbz==""){
        alert("备注不能为空");
        return;
    }
    axios({
        url:'/api/User/AddUser',
        method:'post',
        data:info
    })
    .then((res)=>{
        if(res.data>0){
            alert("添加成功")
            router.push('/userList')
            return
        }
        else
        {
            alert("添加失败")
            return;
        }
    })
}
</script>

<style scoped>

</style>